package com.itheima.prtice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/co02")
public class SessionServlet02 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //需求：第一个Session中设置共享数据，第二个session中得到共享数据
//        HttpSession session = req.getSession();
//        req.setAttribute("name","aa");容易把值写死
        //-----------------------------------------
//        String name = req.getParameter("name");
//        HttpSession session = req.getSession();
//        session.setAttribute("name",name);
//        resp.setContentType("text/html;charset=utf-8");
        String username = req.getParameter("username");
        HttpSession session = req.getSession();
        session.setAttribute("username", username);


    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
